package com.jkzx.view;

import android.content.Context;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.MotionEvent;

public class MyViewPage extends ViewPager{
	private float mLastMotionX;

	public MyViewPage(Context context) {
		super(context);
	}

	public MyViewPage(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

	@Override
	public boolean onInterceptTouchEvent(MotionEvent ev) {
		System.out.println("MyViewPage onInterceptTouchEvent");
		System.out.println(ev.getY()+"a");
		if(ev.getY()<320){
			System.out.println("ev.getY()<320");
			getParent().requestDisallowInterceptTouchEvent(true);
			return false;//true viewPage可以使用
		}
		final int action = ev.getAction();
		final float x = ev.getX();
		switch (action) {
			case MotionEvent.ACTION_DOWN:
				mLastMotionX = x;
				break;
			case MotionEvent.ACTION_MOVE:
				final float dx = x - mLastMotionX;
				System.out.println(ev.getY()+"b");
				if(/*dx>0&&*/getCurrentItem()==0) {
					System.out.println("getCurrentItem()==0");
					System.out.println(ev.getY()+"a");
					if(ev.getY()<320){
						System.out.println("ev.getY()<320");
						getParent().requestDisallowInterceptTouchEvent(true);
						return false;//true viewPage可以使用
					}
					else{
						if(dx>0)
							return false;
					}
				}
				break;
		}
		return true;
	}
}